package com.murphy.log.controller;

import com.murphy.log.service.LogService;
import com.murphy.utils.PageController;
import com.murphy.utils.PageDataMaker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Murphy
 * @Date 2018-01-17 17:37
 */
@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @RequestMapping("list")
    public ModelAndView list(@ModelAttribute("logListForm")PageController pageController, HttpServletRequest request){
        Map<String,Object> map = new HashMap<String, Object>();
        pageController.setSrchField(map);
        pageController.loadPage(new PageDataMaker() {
            @Override
            public List<?> getPageList(int startRow, int countPerPage, String orderColumn, String orderType, Map<String, Object> srchMap) {
                return logService.getLogListPage(srchMap,startRow,countPerPage);
            }

            @Override
            public int getTotalCount(Map<String, Object> srchMap) {
                return logService.getLogListCount(srchMap);
            }
        });
        request.setAttribute("logList",pageController.getPageList());
        request.setAttribute("count",pageController.getTotalCount());
        return new ModelAndView();
    }

}
